package com.vdf.sisconsolid.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public final class UtilSC {

	public static boolean isEmptyString(String string) {
		return string == null || string.trim().equals("");
	}

	// convert InputStream to String
	public static String getStringFromInputStream(InputStream is) {

		BufferedReader br = null;
		StringBuilder sb = new StringBuilder();

		String line;
		try {

			br = new BufferedReader(new InputStreamReader(is));
			while ((line = br.readLine()) != null) {
				sb.append(line);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}

		return sb.toString();

	}

	public static String generatePrittyAddress(String street, Integer number,
			String floor, String department, String block, String lot,
			String neighborhood, String province, String city) {
		String prittyAddress = "";
		if (!isEmptyString(street)) {
			prittyAddress += street + " ";
		}
		if (number != null) {
			prittyAddress += number;
		}
		if (!isEmptyString(floor)) {
			prittyAddress += ", " + floor + department + " ";
		}

		if (!isEmptyString(block)) {
			prittyAddress += ", Mza " + block + " Lote " + lot;
		}
		if (!isEmptyString(neighborhood)) {
			prittyAddress += " " + neighborhood;
		}
		prittyAddress += ", " + city + " " + province;

		return prittyAddress;
	}
}
